<?php
/// O'My Friends: Personal Social Network Graph on Facebook
/// author : Minkyu Shim (minkyu.shim@gmail.com
//Note : even if $entry is not exist, Facebook doesn't provide any error or message
function callGraphAPI($entry){
    
    global $facebook;
    
    $data = null;
        
    if($facebook->getUser()){
        if(!empty($entry)){
            try{
                $now = time();
                $data = $facebook->api($entry);
                error_log("callGraphAPI(".$entry.") success : ".(time() - $now));
            }catch(FacebookApiException $e){
                error_log("callGraphAPI(".$entry.") fail : ".(time() - $now).$e->getMessage());
                throw $e;
            }
        }
    }
    return $data;    
}

function callFQL($query){

    global $facebook;

    $data = null;
    if($facebook->getUser()){
        if(!empty($query)){
            try{
                $now = time();
                $data = $facebook->api(array(
                    'method' => 'fql.query',
                    'query' => $query
                ));
                error_log("callFQL success : ".(time() - $now)).$query;
            }catch(FacebookApiException $e){
                error_log("callFQL fail : ".(time() - $now)).$e->getMessage().$query;
                throw $e;
            }
        }
    }else{
        throw new Exception("no session");
    }
    return $data;

}

//Note : even if $entry is not exist, Facebook doesn't provide any error or message
function callMultiFQL($queries){
    
    global $facebook;

    $data = null;
    if($facebook->getUser()){
        if(!empty($queries) && is_array($queries)){
            try{
                $now = time();
                $data = $facebook->api(
                    array(
                    	'method' => 'fql.multiquery',
                        'queries' => $queries
                    )
                );
                error_log("callMultiFQL success : ".(time() - $now)).substr(print_r($queries, true),0,50);
            }catch(FacebookApiException $e){
                error_log("callMultiFQL fail : ".(time() - $now))." ".$e." ".substr(print_r($queries, true),0,50);
                throw $e;
            }
        }
    }
    return $data;   
}
